<!--Descriptive page name, messages and instructions-->
<div class="tag profile">
  <div class="header module">
    <h2><%= @tag.name %></h2>
    <% if can_wrangle? %>
    <ul class="navigation" role="navigation">
      <li><%= link_to 'Edit', {:controller => :tags, :action => :edit, :id => @tag} %> </li>
      <li><%= tag_comment_link(@tag) %></li>  
    </ul>
    <% end %>
  </div>

  <%= error_messages_for :tag %>
  <!--/descriptions-->

  <!--main content-->
  <p><%= ts("This tag belongs to the") %> <%= @tag.class::NAME %> <%=h "Category" %>.
  <% if @tag.canonical %>
    <%= ts("It's a common tag. You can use it to ") %> 
    <%= link_to 'filter works', {:controller => :works, :action => :index, :tag_id => @tag} %> <%= ts('and to') %> 
    <%= link_to "filter bookmarks", {:controller => :bookmarks, :action => :index, :tag_id => @tag} %>.
  <% end %>
  </p>
  

  <% if @tag.is_a?(Rating) && @tag.adult %>
  <p class="warning"><%= ts('This tag indicates adult content.') %></p>
  <% end %>

  <% if @tag.is_a?(Fandom) %>
  <div class="module">
	  <h3><%= ts('Parent tags (more general)') %>:</h3>
    <ul class="tags">
	  <% (@tag.parents + [@tag.media]).uniq.compact.sort.each do |parent| %>
      <li><%= link_to_tag parent %></li>
    <% end %>
    </ul>
  </div>
  <% else %>
    <% unless @tag.parents.blank? %>
    <div class="module">
      <h3><%= ts('Parent tags (more general)') %>:</h3>
      <ul class="tags"><%= tag_link_list(@tag.parents.sort) %></ul>
    </div>
    <% end %>
  <% end %>

  <% if @tag.merger %>
  <div class="module">
    <h3>Mergers</h3>
    <p><%= @tag.name %> <%= ts('has been merged into') %> <%= link_to_tag @tag.merger %> <%=h 'for filtering.' %> <%= ts('Works and bookmarks tagged with') %> <%= @tag.name %> <%= ts('will show up in') %> <%= link_to @tag.merger.name + "'s", {:controller => :works, :action => :index, :tag_id => @tag.merger} %> <%=h 'filter.' %></p>
  </div>
  <% end %>

  <% unless @tag.mergers.blank? %>
  <div class="module">
    <h3><%= ts('Tags with the same meaning') %>:</h3>
    <ul class="tags"><%= tag_link_list(@tag.mergers) %></ul>
  </div>
  <% end %>

  <% unless @tag.direct_meta_tags.blank? %>
  <div class="module">
    <h3><%= ts('Meta tags') %>:</h3>
    <%= meta_tag_tree(@tag) %>
  </div>
  <% end %>

  <% unless @tag.direct_sub_tags.blank? %>
  <div class="module">
    <h3><%= ts('Sub tags') %>:</h3>
    <%= sub_tag_tree(@tag) %>
  </div>
  <% end %>

  <% unless @tag.children.blank? %>
  <div class="module">
  <h3><%= ts('Child tags (more specific)') %>:</h3>
  <% @tag.children.uniq.compact.sort.group_by(&:type).each do |type, tags| %>
    <h4><%= type.to_s.pluralize %>:</h4>
    <ul class="tags"><%= tag_link_list(tags) %></ul>
  <% end %>
  </div>
  <% end %>

  <% if @works %>

  <p><%= ts("This tag has not been marked common and can't be filtered on (yet).") %></p>
  
  <% unless @works.blank? %>
  <div class="module">
  <h3><%= ts('Works which have used it as a tag') %>:</h3>
    <%= paginated_section @works, {:previous_label => '&laquo; Previous', :next_label => 'Next &raquo;'} do %>
      <ul class="work index">
        <% for work in @works %>
          <%= render :partial => 'works/work_blurb', :locals => {:work => work} %>
        <% end %>
      </ul>
    <% end %>
  </div>
  <% end %>

  <% unless @bookmarks.blank? %>
  <div class="module">
  <h3><%= ts('Bookmarks which have used it as a tag') %>:</h3>
    <%= paginated_section @bookmarks, {:previous_label => '&laquo; Previous', :next_label => 'Next &raquo;'} do %>
      <ul class="bookmark work index">
        <% for bookmark in @bookmarks %>
          <%= render :partial => 'bookmarks/bookmark', :locals => {:bookmark => bookmark} %>
        <% end %>
      </ul>
    <% end %>
  </div>
  <% end %>

  <% end %>
</div>
<!--/content-->
